public class Leetcode2379 {

    public static void main(String[] args) {
        System.out.println(minimumRecolors("WBBWWBBWBW", 7));
        System.out.println(minimumRecolors("BWWWBB", 6));
    }

    public static int minimumRecolors(String blocks, int k) {
        char[] blocksChar = blocks.toCharArray();

        int res = Integer.MAX_VALUE;
        int wCount = 0;
        for (int i = 0; i < blocksChar.length; i++) {
            if (blocksChar[i] == 'W') {
                wCount++;
            }

            if (i >= k && blocksChar[i - k] == 'W') {
                wCount--;
            }

            if (i >= k - 1 && wCount < res) {
                res = wCount;
            }
        }

        return res;
    }


}
